<?php defined('SYSPATH') or die('No direct script access.');

/**
 * @example 三种情况
 *
 */
class Model_Tools extends Model_Database {

	private $_config;

	public function __construct()
	{
		parent::__construct();
		
		$this->_config = Kohana::$config->load('tools');
	}


	public function clean_all_cache()
	{
		//删除系统缓存
		$this->delete_allcache();
		foreach ($this->_config['cache_path'] as $value)
		{
			rmdir_recursive($value, TRUE);
			@touch($value.'/index.htm');
		}
	}

	public function create_static_folder()
	{
		$target_path = normalize_path(MODPATH.'/../../static');
		$link_path = normalize_path(APPPATH . '/static/common');
		
		@unlink($link_path);@rmdir($link_path);
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && version_compare(php_uname('r'), '6.0', '<')) { //Windows Vista以下
			exec('"'.$target_path.'/bin/junction.exe" -d "'.$link_path.'"');
			exec('"'.$target_path.'/bin/junction.exe" "'.$link_path.'" "'.$target_path.'"');
		} else {
			@symlink($target_path, $link_path);
		}
	}
}